#include <iostream>
#include <vector>
using namespace std;

class Solution {
        int max_profit(vector<int> &prices)
        {
                int n = prices.size();
                vector<int> cost;
                for(int i = 1; i < n; i++){
                        cost.push_back(prices[i] - prices[i - 1]);
                }
                if(cost.size() == 0){
                        return 0;
                }

                vector<int> dp(cost.size(), 0);
                dp[0] = cost[0];
                int ans = max(0, dp[0]);

                for(int i = 1; i < cost.size(); i++){
                        dp[i] = max(cost[i], cost[i] + dp[i - 1]);
                        ans = max(ans, dp[i]);
                }
                return ans;
        }

        int max_profit_dp(vector<int> &prices)
        {
                int n = prices.size();
                vector<vector<int>> dp(n, vector<int>(2, 0));
                dp[0][1] = -prices[0];
                dp[0][0] = 0;

                for(int i = 1; i < n; i++){
                        dp[i][1] = max(dp[i - 1][1], -prices[i]);
                        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]);
                }

                return max(dp.back()[0], dp.back()[1]);
        }
    public:
	int maxProfit(vector<int> &prices)
	{
                return max_profit(prices);
        }
};

int main()
{
	vector<int> price{ 1, 2 };
	cout << Solution().maxProfit(price) << endl;
	return 0;
}